
//
//  HMStatusOriginalFrame.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/14.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusOriginalFrame.h"
#import "HMStatus.h"
#import "HMUser.h"
#import "HMStatusPhotosView.h"

@implementation HMStatusOriginalFrame

//重写 status 的setter 方法
- (void)setStatus:(HMStatus *)status{

    _status = status;
    
    //1.头像
    CGFloat iconX = HMStatusCellInset;
    CGFloat iconY = HMStatusCellInset;
    CGFloat iconW = 35;
    CGFloat iconH = 35;
    self.iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    //2.昵称
    CGFloat nameX = CGRectGetMaxX(self.iconFrame) + HMStatusCellInset;
    CGFloat nameY = iconY;
        
    CGSize nameSize = [status.user.name sizeWithAttributes:@{NSFontAttributeName:HMStatusOriginalNameFont}];
    self.nameFrame = (CGRect){{nameX, nameY}, nameSize};
    //3.计算会员图标的位置
    //如果是会员身份
    if (status.user.isVip) {
        CGFloat vipX = CGRectGetMaxX(self.nameFrame) + HMStatusCellInset;
        CGFloat vipY = nameY;
        CGFloat vipH = nameSize.height;
        CGFloat vipW = vipH;
        
        self.vipFrame = CGRectMake(vipX, vipY, vipW, vipH);
    }
    
    
    
    
    //6.正文
    CGFloat textX = iconX;
    CGFloat textY = CGRectGetMaxY(self.iconFrame) + HMStatusCellInset * 0.5;
    CGFloat maxW = kScreenWidth - 2 * textX;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
    CGSize textSize = [status.text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:HMStatusOriginalTextFont} context:nil].size;
    self.textFrame = (CGRect){{textX, textY}, textSize};
    
    
    //7.配图相册
    CGFloat h = 0;
    if (status.pic_urls.count) {
        CGFloat photosX = textX;
        CGFloat photosY = CGRectGetMaxY(self.textFrame) + HMStatusCellInset;
        CGSize photosSize = [HMStatusPhotosView sizeWithPhotosCount:(int)status.pic_urls.count];
        
        self.photosFrame = (CGRect){{photosX, photosY}, photosSize};
        
        h = CGRectGetMaxY(self.photosFrame) + HMStatusCellInset;
        
    }else{
       h = CGRectGetMaxY(self.textFrame) + HMStatusCellInset;
    }
    
    
      //8.自己frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = kScreenWidth;
    
    self.originalF = CGRectMake(x, y, w, h);
}


@end
